<? 
	include('base.php');
	User::protect();
	$section = 'band_diaries';
	$db = new db;
	include_class('band_diaries');
	include_class('band_members');
	
	$bm = BandMember::get($_REQUEST['memberID']);
	if (!db::isError($bm)) {
		$uo = $bm->getUserObject();
		if ($_POST['submit']) { 
			// add news entry
			$bd = BandMemberDiary::add($_POST);
			if (!db::isError($bd)) {
				header('Location: band_diary_edit.php?id=' . $bd->getID());
			}
		}
	}
	
	$calendar = true;	
	$editors = array('body');
	$page_title = 'Add Band Diary';
	include('layout/header.php');
	

	// This page requires a member_id get variable. If it's not present we forward to it if the user isn't admin
	// and if the user admin, we go back to the band_diaries page

?>

<? if (!db::isError($bm)) {

if ($bm->canEdit()) { ?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_diaries.php">Diaries&nbsp;&#62;</a>&nbsp;<a href="band_diaries.php?memberID=<?=$_GET['memberID']?>"><?=$uo->getFirstName()?>'s Diary&nbsp;&#62;</a>&nbsp;Add Diary Entry
</div>

	<? if (db::isError($bd)) {
		$bd->outputList();
	} ?>

	<h1>new diary entry:</h1>
	<div class="inset">
	<form id="add_new_entry" action="<?=$_SERVER['PHP_SELF']?>" method="post">
	<table border="0" class="edit-form" cellspacing="0" cellpadding="0">
	<tr>
		<td colspan="3" valign="top">
		<strong>Headline</strong><br/>
		<input type="text" value="<?=$_POST['title']?>" class="text" name="title">
		</td>
	</tr>
	<tr>
		<td width="50%" valign="top">
		
		<? 
		
		$date = ($_POST) ? $_POST['date'] : db::get_local_datetime(DATE_FORMAT);
		$time = ($_POST) ? $_POST['time'] : db::get_local_datetime(TIME_FORMAT);
		
		?>
		
		<strong>Date (<a style="vertical-align: middle" href="javascript:void(0)" onclick="popUpCalendar(this, document.getElementById('date'), '<?=DATE_JS_CALENDAR?>')">Calendar</a>)</strong><br/>
		<input name="date" id="date" class="text" type="text" value="<?=$date?>">
		
		</td>
		<td width="50%" valign="top">
					
		<strong>Time</strong><br/>
		<input name="time" id="time" class="text" type="text" value="<?=$time?>">
		</td>

	</tr>
	</table>
	<div class="edit-form">
	<strong>Body</strong><br/><textarea id="body" name="body" class="full"><?=$_POST['body']?></textarea>
	</div>
	<input type="hidden" name="member_id" value="<?=$_REQUEST['memberID']?>">
	<input type="hidden" name="memberID" value="<?=$_REQUEST['memberID']?>">
	
	<input type="submit" value="Add Entry" name="submit" class="button">
	<input type="submit" class="button" value="Return to Diary" name="preview" onclick="location.href='band_diaries.php?memberID=<?=$bm->getID()?>'; return false" class="button">
	</form>
	</div>

<? } else { ?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_diaries.php">Diaries&nbsp;&#62;</a>&nbsp;<a href="band_diaries.php?memberID=<?=$_GET['memberID']?>"><?=$uo->getFirstName()?>'s Diary&nbsp;&#62;</a>&nbsp;No Access
</div>

	<? Error::outputDialog('Return to Band Diaries','band_diaries.php', 'You do not have permission to add an entry to this diary.')?>

<? } ?>

<? } else { ?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_diaries.php">Diaries&nbsp;&#62;</a>&nbsp;Invalid Band Member
</div>

	<?=$bm->outputDialog('Return to Band Diaries','band_diaries.php')?>
<? } ?>

<? include('layout/footer.php'); ?>
